package com.hrt.datasender.web.logmonitor;

import com.btcode.web.core.annotation.RequestMapping;
import com.btcode.web.core.controller.Controller;
import com.hrt.common.web.DSRequestUnit;
import com.hrt.datasender.mq.model.LogModel;
import com.hrt.log.LogMonitor;
import com.hrt.log.MonitorModel;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author gislin
 *
 */
@RequestMapping(path = "LogMonitor")
public class LogMonitorController extends Controller {

    @RequestMapping(path = "getList")
    public void getList(ServletRequest arg0, ServletResponse arg1) throws IOException {

        List<MonitorModel> models = LogMonitor.getInstance().getMonitorModelList();
        success(models);
    }

    @RequestMapping(path = "getListByPrefix")
    public void getListByPrefix(ServletRequest arg0, ServletResponse arg1) throws IOException {

        String monitorIdPrefix = DSRequestUnit.getString("monitorIdPrefix");
        List<MonitorModel> models = LogMonitor.getInstance().getMonitorModelListByPrefix(monitorIdPrefix);

        success(models);
    }

    @RequestMapping(path = "getLogMsgList")
    public void getLogMsgList(ServletRequest arg0, ServletResponse arg1) throws IOException {

        String monitorId = DSRequestUnit.getString("monitorId");
        List<LogModel> models = LogMonitorService.getInstance().getLogModelList(monitorId);

        success(models);
    }

    @RequestMapping(path = "getLogMsg")
    public void getLogMsg(ServletRequest arg0, ServletResponse arg1) throws IOException {

        String monitorId = DSRequestUnit.getString("monitorId");
        LogModel model = LogMonitorService.getInstance().getOneLogModel(monitorId);

        success(model);
    }

    @RequestMapping(path = "getErrorLogMsgList")
    public void getErrorLogMsgList(ServletRequest arg0, ServletResponse arg1) throws IOException {

        String monitorId = DSRequestUnit.getString("monitorId");
        List<LogModel> models = LogMonitorService.getInstance().getErrorLogModelList(monitorId);

        success(models);
    }

    @RequestMapping(path = "getErrorLogMsg")
    public void getErrorLogMsg(ServletRequest arg0, ServletResponse arg1) throws IOException {

        String monitorId = DSRequestUnit.getString("monitorId");
        LogModel model = LogMonitorService.getInstance().getOneErrorLogModel(monitorId);

        success(model);
    }

    @RequestMapping(path = "clearMsg")
    public void clearMsg(ServletRequest arg0, ServletResponse arg1) {
        String monitorId = DSRequestUnit.getString("monitorId");
        LogMonitorService.getInstance().clearMsg(monitorId);
    }

}
